package com.study.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author zhaobo
 * @Date 2020/04/25
 */
public class TestServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.process(req, resp);
    }


    private void process(HttpServletRequest req, HttpServletResponse resp){
        //想浏览器发送数据类型
        resp.setContentType("text/html");
        //获取输出流
        PrintWriter out = null;
        try {
            out = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置要输出的数据
        out.println("<h1>HelloWorld!</h1>");
        //关闭流
        out.close();
    }

}
